package com.ycp.erp.bill.ui.binder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.bill.model.bean.Bill;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/9/7.
 */
public class BillManagerBinder extends BaseItemBinder<Bill> {
    public BillManagerBinder() {
        super(R.layout.item_bill_manager);
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, @NonNull Bill item) {
        TextView tvStatus= holder.getView(R.id.tvStatus);
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        if (item.getStatue()==1){
            tvStatus.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().getDrawable(R.drawable.red_w_dot),null,null,null);
            tvStatus.setText("赊账中");
            tvStatus.setTextColor(mContext.getResources().getColor(R.color.root_red));
        }else {
            tvStatus.setCompoundDrawablesWithIntrinsicBounds(mContext.getResources().getDrawable(R.drawable.green_w_dot),null,null,null);
            tvStatus.setText("已结账");
            tvStatus.setTextColor(0xff59C44B);
        }
        if (item.isSelect()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        ivSelect.setOnClickListener(v -> {
            item.setSelect(!item.isSelect());
            if (item.isSelect()) {
                ivSelect.setImageResource(R.mipmap.ic_selected_circle);
            } else {
                ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
            }
        });
        holder.getView(R.id.tvDetail).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RouterManager.getInstance().go(RouterPath.PROTURE_ENTER_WAREHOUSE);
            }
        });
    }
}
